package com.luoqiu.cinema.config;

import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authc.credential.CredentialsMatcher;
import org.springframework.stereotype.Component;

/**
 * @author 洛秋y
 * @date 2020/11/27 13:29
 */
@Component
public class MyCredentialsMatcher implements CredentialsMatcher {
    @Override
    public boolean doCredentialsMatch(AuthenticationToken authenticationToken, AuthenticationInfo authenticationInfo) {
        UsernamePasswordToken utoken = (UsernamePasswordToken) authenticationToken;
        //获得用户输入的密码:(可以采用加盐(salt)的方式去检验)
        String inPassword = new String(utoken.getPassword());
        //String username = utoken.getUsername();
        //获得数据库中的密码
        String dbPassword = (String) authenticationInfo.getCredentials();
        return inPassword.equals(dbPassword);
    }
}
